package main

import (
	"log"
	"runtime"
	"encoding/json"
	"github.com/nats-io/nats.go"
)

func main() {

	var url = "nats://127.0.0.1:4222"

	nc, err := nats.Connect(url, nats.Name("dalongdemo"))

	if err != nil {

		log.Fatal("connect error")

	}

	nc.Subscribe("dalong", func(mess *nats.Msg) {
		log.Println(string(mess.Data), "from nats")
		result, _ := json.Marshal(mess)
		log.Println("the reply info is ", string(result))
		nc.Publish(mess.Reply,[]byte("dalong can help you"))
		log.Println(mess.Reply)

	})

	runtime.Goexit()
}